app.config(function($stateProvider, $urlRouterProvider) {
  $stateProvider
   /*----------------组织岗位配置管理----------------------*/
  .state('organization_categories', {
    url: '/organization/categories',
    templateUrl: 'app/partials/organizations/categories/index.html',
    controller: function($scope,OrganizationCategory,$location) {
      $scope.widget_title = '组织岗位配置管理';   
      $scope.categories= OrganizationCategory.query() ;

      $scope.category_position_standard = function(item){
        $location.url("/organization/categories/" + item + "/position_standard")
      }

      /* 删除 记录*/
      $scope.itemDelete = function(item){
        OrganizationCategory.delete({},{"id": $scope.categories[item].name})
        $scope.categories.splice(item, 1); 
      }
      
   }
  })

  .state('organization_categories.new', {
    url: '/new',
    templateUrl: 'app/partials/organizations/categories/new.html',
    controller: function($scope,OrganizationCategory) {
      $scope.widget_title = '添加组织类型';   

      $scope.update = function(category){
        OrganizationCategory.save(category, function(nr){
          $scope.categories.push(nr["result"]);
          console.log(nr)
          $scope.category = {}
        });
      }

   }
  })

  .state('organization_categories.show', {
    url: '/:id/position_standard',
    templateUrl: 'app/partials/organizations/categories/show.html',
    controller: function($scope,OrganizationCategory, $stateParams, OrganizationCategoryPositionStandard) {
      $scope.widget_title = $stateParams.id + '-组织类型岗位一览表';   
      $scope.organ_category_position_standards = OrganizationCategoryPositionStandard.query_position_standard({category: $stateParams.id});
      /* 删除 记录*/
      $scope.itemDelete = function(item){
        OrganizationCategoryPositionStandard.delete({},{"id": $scope.organ_category_position_standards[item].id})
        $scope.organ_category_position_standards.splice(item, 1); 
      }
   }
  })

  .state('organization_categories.show.add_position', {
    url: '/new',
    templateUrl: 'app/partials/organizations/categories/add_position.html',
    controller: function($scope,OrganizationCategory, Position, $state, $stateParams, OrganizationCategoryPositionStandard) {
      $scope.widget_title = '添加岗位';   
      $scope.positions = Position.query() ;

      console.log($stateParams.id)

      $scope.update = function(data){
        data.organization_category = $stateParams.id
        OrganizationCategoryPositionStandard.save(data, function(nr){
          // $scope.position_certificate_standards.push(nr["result"]);
          // console.log(nr)
        });
        $state.transitionTo('organization_categories.show',$stateParams,{reload: true});  
        
      }
   }
  })
})